﻿@model OpenAuth.Domain.Module
@{
    ViewBag.Title = "Module编辑界面";
    Layout = null;
}

<div class="bjui-pageContent">
    <form action="/ModuleManager/Add" class="pageForm" data-toggle="validate">
        <table class="table table-condensed table-hover">
            <tbody>
             
                <tr>
                    <td>
                        @Html.HiddenFor(m => m.Id)
                        @Html.HiddenFor(m =>m.CascadeId)
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="Name" class="control-label x120">功能模块名称：</label>
                        <input type="text" name="Name" id="Name" value="@Model.Name"
                               data-rule="required" size="20">
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="Url" class="control-label x120">主页面URL：</label>
                        <input type="text" name="Url" id="Url" value="@Model.Url"  size="20">
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="ParentId" class="control-label x120">上级功能模块：</label>
                        <input id="ParentId" name="ParentId" value="@Model.ParentId" style="display: none" />
                        <input type="text" name="ParentName" id="ParentName" size="20"
                               value="@Model.ParentName"
                               @if (Model.Id == 0)
                               {
                                   <text> data-toggle="selectztree" data-tree="#j_select_tree1"</text>
                               }
                               else
                               {
                                   //TODO:修改的时候暂不能修改结构，因为以下：
                                   //如果在前台处理，不能处理自身的ID
                                   //如果在后台处理，因为算法会找最大的级联ID进行计算，如果每次都执行算法，肯定不行
                                   //如果判断前端是否修改组织，再到后台处理，会增加前端的复杂程序
                                   <text>readonly="readonly"</text>
                               } />

                        <ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
                    </td>

                </tr>
               
                <tr>
                    <td>
                        <label for="IconName" class="control-label x120">节点图标文件名称：</label>
                        <input type="text" name="IconName" id="IconName" value="@Model.IconName"  size="20">
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="Status" class="control-label x120">当前状态：</label>
                        <select name="Status" id="Status" data-toggle="selectpicker" data-rule="required">
                            <option value="0" @if (Model.Status == 0) { <text> selected="selected" </text>   }>默认</option>
                            <option value="1" @if (Model.Status == 1) { <text> selected="selected" </text>   }>状态1</option>
                        </select>
                    </td>
                </tr>
              
                <tr>
                    <td>
                        <label for="Vector" class="control-label x120">矢量图标：</label>
                        <input type="text" name="Vector" id="Vector" value="@Model.Vector" size="20">
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="SortNo" class="control-label x120">排序号：</label>
                        <select name="SortNo" id="SortNo" data-toggle="selectpicker" data-rule="required">
                            <option value="0" @if (Model.SortNo == 0) { <text> selected="selected" </text>   }>默认</option>
                            <option value="1" @if (Model.SortNo == 1) { <text> selected="selected" </text>   }>状态1</option>
                        </select>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close">关闭</button></li>
        <li><button type="submit" class="btn-green">保存</button></li>
    </ul>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        Init();
    });
    function Init() {
        var setting = {
            view: {
                selectedMulti: false
            },
            check: {
                enable: true,
                chkStyle: "radio",
                radioType: "all"
            },
            data: {
                key: {
                    name: 'Name',
                    title: 'Name'
                },
                simpleData: {
                    enable: true,
                    idKey: 'Id',
                    pIdKey: 'ParentId',
                    rootPId: 'null'
                }
            },
            callback: {
                onClick: zTreeOnClick,
                onCheck: zTreeCheck
            }
        };
        $.getJSON('ModuleManager/LoadModuleWithRoot', function (json) {
            var zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json);
            zTreeObj.expandAll(true);
        });
    }

    function zTreeCheck(e, treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj(treeId),
            nodes = zTree.getCheckedNodes(true);
        var ids = '', names = '';
        for (var i = 0; i < nodes.length; i++) {
            ids += ',' + nodes[i].Id;
            names += ',' + nodes[i].Name;
        }
        if (ids.length > 0) {  //去掉第一个逗号
            ids = ids.substr(1);
            names = names.substr(1);
        }

        var $from = $('#' + treeId).data('fromObj');
        if ($from && $from.length) $from.val(names);

        $('#ParentId').val(ids);
    }
    function zTreeOnClick(event, treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj(treeId);
        zTree.checkNode(treeNode, !treeNode.checked, true, true);
        event.preventDefault();
    }
</script>